{# 以下是分页  #}
<div>
    <nav aria-label="Page navigation">
        <ul class="pagination">
            <li class="disabled">
                <span>每页显示</span>
            </li>
            <li>
                            <span>
                                <select class="line_count" id="line_set" line_count= {{  line_count }}  name="line_count">
                                    <option>5</option>
                                    <option>10</option>
                                    <option>15</option>
                                    <option>20</option>
                                </select>
                            </span>
            </li>

            <li>
                <a href="{{ request.path }}?page=1&line_count={{ line_count  }}&user_search={{ search }}" aria-label="Previous">
                    <span aria-hidden="true">第一页</span>
                </a>
            </li>

            {% if current_page.has_previous %}
                <li>
                    <a href="{{ request.path }}?page={{ current_page.previous_page_number }}&line_count={{ line_count  }}&user_search={{ search }}" aria-label="Previous">
                        <span aria-hidden="true">上一页</span>
                    </a>
                </li>
            {% else %}
                <li class="disabled">
                    <a href="" aria-label="Previous">
                        <span aria-hidden="true">上一页</span>
                    </a>
                </li>
            {% endif %}
            {# 拿到页码书总列表 #}
            {% for item in  page_range %}
                {% if current_page_num == item %}
                    <li class="active"><a href="{{ request.path }}?page={{ item }}&line_count={{ line_count  }}&user_search={{ search }}">{{ item }}</a></li>
                {% else %}
                    <li ><a href="{{ request.path }}?page={{ item }}&line_count={{ line_count  }}&user_search={{ search }}">{{ item }}</a></li>
                {% endif %}
            {% endfor %}

            {% if current_page.has_next %}
                <li>
                    <a href="{{ request.path }}?page={{ current_page.next_page_number }}&line_count={{ line_count  }}&user_search={{ search }}" aria-label="Next">
                        <span aria-hidden="true">下一页</span>
                    </a>
                </li>
            {% else %}
                <li class="disabled">
                    <a href="" aria-label="Previous">
                        <span aria-hidden="true">下一页</span>
                    </a>
                </li>
            {% endif %}
            <li>
                <a href="{{ request.path }}?page={{ last_page }}&line_count={{ line_count  }}&user_search={{ search }}" aria-label="Previous">
                    <span aria-hidden="true">最后一页</span>
                </a>
            </li>
            <li class="disabled">
                <span>跳转到</span>
            </li>
            <li>

                                <span>
                                    <select id="page_set" page_set= {{ current_page_num }}>
                                                    <script >
                                                        for(var i=1;i<={{ paginator.num_pages }};i++){
                                                            document.write("<option value='"+i+"'>"+i+"</option>");
                                                        }
                                                    </script>
                                    </select>
                                </span>
            </li>

            <li class="disabled">
                <a href="" aria-label="Previous">
                    <span aria-hidden="true">共 {{ paginator.num_pages }} 页 , {{ paginator.count }} 条 </span>
                </a>
            </li>
        </ul>
    </nav>
</div>
{#  以上是分页 #}
{% block script %}
    <script>
        $("#line_set").change(function() {
            var line_count_set = $('.line_count').val();
            var search = $('.aa_search').val();
            var   url=window.location.pathname+"?line_count="+line_count_set+"&user_search="+search;
            window.location.href=url;
        })

        $("#page_set").change(function() {
            var line_count_set = $('.line_count').val();
            var page_set = $('#page_set').val();
            var search = $('.aa_search').val();
            var   url=window.location.pathname+"?page="+page_set+"&line_count="+line_count_set+"&user_search="+search;
            window.location.href=url;
        })

        //以下为页面刷新时自加载函数
        window.onload=function() {
            //刷新时,自动加载当前每页显示的条目数
            var count_set = document.getElementById("line_set").getAttribute("line_count");
            document.getElementById("line_set").value = count_set
            //刷新是,加载当前跳转的页数
            var page_set = document.getElementById("page_set").getAttribute("page_set");
            document.getElementById("page_set").value = page_set

            //以下是自动加载搜搜的内容
            var search =  document.getElementById("aa_search").getAttribute("aa_search");
            $('.aa_search').val(search)
        }


    </script>
{% endblock %}

